---
title: "Biased and Unreliable Media Sources"
author: "Asheley R. Landrum"
date: "01/31/2023"
output:
  word_document: default
  html_document:
    df_print: paged
---

Code for reproducing the findings for the current study. Raw data and other study materials are available at our OSF.io project site: https://osf.io/wqxfy/

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(car) #for Recoding data
library(psych) #does a lot of important things
library(tidyverse) #also does a lot of important things
library(ltm)
library(relaimpo)
library(dplyr)
library(haven)


dat = as.data.frame(haven::read_sav("StrydhorstMoralesRiechLandrum.sav"))
```


# Finding 1: Participants who vote for Democrats have less biased media diets on average than participants who typically vote for Republicans.

```{r F1, echo=F, warning=F}

dat$Party3 = factor(dat$Vote3, levels = c(1:3), labels = c("Democrat", "Other", "Republican"))
dat$VoteF = factor(dat$Vote, levels = c(1:5), labels = c("Democrat", "Republican", "Third", "NoVote", "NA"))

f1_res = aov(absBias ~ VoteF, data = dat)
TukeyHSD(f1_res)

figdat = dat%>%
  filter(Party3 == "Democrat" | Party3 == "Republican")

figdat$Vote = relevel(figdat$Party3, ref = "Democrat")

# Media Bias (Absolute Value) Distribution
ggplot(data = figdat, mapping = aes(x = absBias, fill = Vote, color = Vote)) + geom_density(kernel = "gaussian", alpha = .25) + scale_color_manual(values = c("Blue", "Red")) + scale_fill_manual(values = c("Blue", "Red")) + theme_bw() + labs(x = "Average Media Bias Score", title = "Distribution of Participants' Average Media Bias Scores")
```

# Finding 2: Democrats selected more reliable sources on average than Republicans.

```{r F2, echo=F, warning=F}
f2_res = aov(reliable ~ VoteF, data = dat)
TukeyHSD(f2_res)

figdat = dat%>%
  filter(Party3 == "Democrat" | Party3 == "Republican")

figdat$Vote = relevel(figdat$Party3, ref = "Democrat")

# Media Reliable Distribution
ggplot(data = figdat, mapping = aes(x = reliable, fill = Vote, color = Vote)) + geom_density(kernel = "gaussian", alpha = .25) + scale_color_manual(values = c("Blue", "Red")) + scale_fill_manual(values = c("Blue", "Red")) + theme_bw() + labs(x = "Average Media Reliability Score", title = "Distribution of Participants' Average Media Reliability Scores")
```

# Finding 3: Average reliability scores moderate the relationship between L2R media bias scores and holding false beliefs about COVID-19 as well as holding false beliefs about vaccination.

**Note: You must download the PROCESS macro for R to run the following script: https://www.processmacro.org/index.html https://haskayne.ucalgary.ca/CCRAM/resource-hub



## COVID-19 Misinformation Belief Score

```{r process_source, include=F, warning=F}

# Source Process script
# We source the script from the applications folder on a Mac. You will need to update this code to wherever you downloaded the PROCESS macro and you may need to update the file to reflect whichever version of the MACRO you are using.

source("/Applications/processv42/PROCESS v4.2 for R/process.R")
```

```{r covid19, echo=F, warning=F}

dat$bias = dat$L2R_Media_bias

result = process(data = dat, y = "cmisinfo", x = "ideo", m = "bias", w = "reliable", cov=c("age", "educ", "male", "black", "hisp", "income"), model = 14, seed = 31216, jn=1, plot = 1, save = 0)


#if we want conditional values on SD, we use moments = 1
#if we want to specify values, we use wmodval = c(16, 32, 48)
#if we want to use johnson neuman, we use jn=1
```

```{r covid_cond_effect_bias, include=F}

mat1 = matrix(data = c(-6.1841,   34.4850,    0.0436,
                       -1.8950,   34.4850,    0.1390,
                        6.7300,   34.4850,    0.3307,
                       -6.1841,   42.6012,   -0.1900,
                       -1.8950,   42.6012,   -0.0130,
                        6.7300,   42.6012,    0.3430,
                       -6.1841,   47.6400,   -0.3351,
                       -1.8950,   47.6400,   -0.1074,
                        6.7300,   47.6400,    0.3506), nrow = 9, ncol = 3, byrow = T)

df1 = as.data.frame(mat1)
names(df1) = c("bias", "reliability", "covid_misinfo")

df1$Reliability = factor(df1$reliability, levels = c(34.485, 42.6012, 47.6400), labels = c("lower", "middle", "higher"))

df1$Bias = factor(df1$bias, levels = c(-6.1841, -1.8950, 6.7300), labels = c("lower", "middle", "higher"))

##-Figure

relcolors = c("#fed976", "#78c679", "#005a32")

covid_cond_fig = ggplot(data = df1, mapping = aes(x = bias, y = covid_misinfo, color = Reliability, fill = Reliability)) + geom_point(size = 4.5) + theme_bw() + scale_color_manual(values = relcolors) + scale_fill_manual(values = relcolors) + labs(x = "Left-to-Right Media Bias Score", y = "COVID-19 Misinformation Belief", title = "Conditional Effect of Left-to-Right Bias")

```

```{r covid_cond_figure}
print(covid_cond_fig)

rm(mat1, df1, result)
```


## Vaccine Belief Score

```{r vaccine, echo=F, warning=F}

result = process(data = dat, y = "vmisinfo", x = "ideo", m = "bias", w = "reliable", cov=c("age", "educ", "male", "black", "hisp", "income"), model = 14, seed = 31216, jn=1, plot = 1, save = 1)
```

```{r vax_cond_effect_bias, include=F}

mat1 = matrix(data = c(-6.1841,   34.4850,    0.0861,
                       -1.8950,   34.4850,    0.1087,
                        6.7300,   34.4850,    0.1542,
                       -6.1841,   42.6012,   -0.0557,
                       -1.8950,   42.6012,    0.0163,
                        6.7300,   42.6012,    0.1610,
                       -6.1841,   47.6400,   -0.1437,
                       -1.8950,   47.6400,   -0.0411,
                        6.7300,   47.6400,    0.1653), nrow = 9, ncol = 3, byrow = T)

df1 = as.data.frame(mat1)
names(df1) = c("bias", "reliability", "vaccine_misinfo")
df1$Reliability = factor(df1$reliability, levels = c(34.485, 42.6012, 47.64), labels = c("lower", "middle", "higher"))
df1$Bias = factor(df1$bias, levels = c(-6.1841, -1.8950, 6.7300), labels = c("lower", "middle", "higher"))

vax_cond_fig = ggplot(data = df1, mapping = aes(x = bias, y = vaccine_misinfo, color = Reliability, fill = Reliability)) + geom_point(size = 4.5) + theme_bw() + scale_color_manual(values = relcolors) + scale_fill_manual(values = relcolors) + labs(x = "Left-to-Right Media Bias Score", y = "Vaccine Misinformation Belief", title = "Conditional Effect of Left-to-Right Media Bias") 

```

```{r}
print(vax_cond_fig)

rm(mat1, df1, result)
```

# Finding 4: 